<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" href="${req.contextPath}/static/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="${req.contextPath}/static/admin/css/admin.css" />
	</head>
		<div class="page-content-wrap">
				<form class="layui-form">
					<div class="layui-tab" style="margin: 0;">
						<ul class="layui-tab-title">
							<li class="layui-this">文章详情</li>
						</ul>
						<input type="hidden" name="id"
						<#if cmsArticle?exists>
							value="${cmsArticle.id}"
						</#if>
						>
						<div class="layui-tab-content">
							<div class="layui-tab-item"></div>
							<div class="layui-tab-item layui-show">
								<div class="layui-form-item">
									<label class="layui-form-label">文章标题：</label>
									<div class="layui-input-block">
										<input type="text" name="title" required lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input"
										<#if cmsArticle?exists>
											value="${cmsArticle.title}"
										</#if>
										>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">发布时间：</label>
									<div class="layui-input-block">
										<input type="text" name="publicTime" id="publicTime" placeholder="请选择时间" class="layui-input" lay-verify="required">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">图像上传：</label>
									<div class="layui-input-block">
										<#if cmsArticle?exists>
											<button type="button" class="layui-btn" id="file">
												<i class="layui-icon">&#xe67c;</i>上传图片
											</button>
											<img src="${cmsArticle.image}" id="showImg">
										<#else>
										<button type="button" class="layui-btn" id="file">
											<i class="layui-icon">&#xe67c;</i>上传图片
										</button>
										</#if>
									</div>
									<input type="hidden" name="image" id="image">
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">分类栏目：</label>
									<div class="layui-input-block">
										<select name="navigationId" lay-verify="required">
											<option value="">请选择分类栏目</option>
											<#if cmsNavigations?exists>
											<#list cmsNavigations as cmsNavigation>
												<option value="${cmsNavigation.id}"
												<#if cmsArticle?exists>
													<#if cmsNavigation.id == cmsArticle.navigationId>
														selected
													</#if>
												</#if>
												>${cmsNavigation.name}</option>
											</#list>
											</#if>
										</select>
									</div>
								</div>
								<div class="layui-form-item layui-form-text">
									<label class="layui-form-label">文章内容：</label>
									<div class="layui-input-block">
										<textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="lay_editor"></textarea>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">点击数：</label>
									<div class="layui-input-block">
										<input type="number" name="views" required lay-verify="required" placeholder="请输入文章点击数" autocomplete="off" class="layui-input" min="0"
										<#if cmsArticle?exists>
											value="${cmsArticle.views}"
										</#if>
										>
									</div>
								</div>
							<div class="layui-form-item">
								<label class="layui-form-label">是否显示：</label>
								<div class="layui-input-block">
									<input type="checkbox" name="isShow" lay-skin="switch" lay-text="是|否"
									<#if cmsArticle?exists>
										<#if cmsArticle.isShow == 1>
										checked
										</#if>
									</#if>
									>
								</div>
							</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item" style="padding-left: 10px;">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit lay-filter="cmsarticleadd">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
		</div>
		<script src="${req.contextPath}/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="${req.contextPath}/static/admin/js/cmsarticle.js" type="text/javascript" charset="utf-8"></script>

		<script>
            layui.use(['laydate','layedit','form'],function () {
                laydate = layui.laydate
				,form = layui.form
				,layedit = layui.layedit
                laydate.render({
                    elem: '#publicTime'
                    ,type: 'datetime'
                    <#if cmsArticle?exists>,value: "${cmsArticle.publicTime?string('yyyy-MM-dd HH:mm:ss')}"</#if>
					,trigger: 'click'
                });
                //layedit.set必须在layedit.build前面
                layedit.set({
                    uploadImage: {
                        url: '/admin/cmsarticle/upload' //接口url
                        ,type: '' //默认post
                    }
                });
                var index = layedit.build('lay_editor', {
                    tool: ['strong' //加粗
                        , 'italic' //斜体
                        , 'underline' //下划线
                        , 'del' //删除线
                        , '|' //分割线
                        , 'left' //左对齐
                        , 'center' //居中对齐
                        , 'right' //右对齐
                        , 'link' //超链接
                        , 'unlink' //清除链接
                        , 'image' //插入图片
                    ],
                    height: 100
                });
            	<#if cmsArticle?exists>
					var content = '${cmsArticle.content?js_string}';
					layedit.setContent(index, content, false);
            	</#if>
                //编辑
                form.on("submit(cmsarticleadd)",function (data) {
                    data.field.content = layedit.getContent(index);
                    if(data.field.isShow == "on"){
                        data.field.isShow = 1;
                    }else {
                        data.field.isShow = 0;
                    }
                    $.ajax({
                        url:'/admin/cmsarticle/add',
                        contentType:'application/json',
                        type:'post',
                        data:JSON.stringify(data.field),
                        dataType:'json',
                        success:function (data) {
                            if(data.code == 500){
                                layer.msg(data.msg);
                            }else if(data.code == 200){
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                parent.table.reload('cmsarticletable');
                            }
                        },
                        error:function (data) {
                            layer.msg("服务异常");
                        }
                    });
                    return false;
                });

			});
		</script>
	</body>

</html>